<?php

namespace app\admin\controller;

use app\common\controller\Backend;

use think\Controller;
use think\Request;
use think\Config;
use think\Db;
use think\Log;

/**
 *
 *
 * @icon fa fa-circle-o
 */
class Allrepay extends Backend
{

    /**
     * BorrowRepay模型对象
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('BorrowRepay');

    }

    public function index()
    {
        //设置过滤方法
        //$this->request->filter(['strip_tags', 'htmlspecialchars']);

        $this->relationSearch = true;

        $this->searchFields = "borrow.borrowId";

        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model->with("borrow,user")
                ->where($where)
                ->order($sort, $order)
                ->count();

            $list = $this->model->with("borrow,user")
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            foreach($list as $key => $val){
                $list[$key]['qishu'] = $val['period'].'/'.$val['totalPeriod'];
            }

            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }




}
